package com.srh.stockmanager.dao;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.srh.stockmanager.entity.User;

/**
 * 
 * @author Sebastian R Helguera (srhelguera@hotmail.com)
 * @version 01/04/2012
 */
@Repository
public class UserDAOImpl implements UserDAO {

	@Autowired
	private SessionFactory sessionFactory;

	public void addUser(User user) {
		sessionFactory.getCurrentSession().save(user);
	}

	@SuppressWarnings("unchecked")
	public List<User> listUser() {

		List<User> list = sessionFactory.getCurrentSession().createQuery("from User")
				.list();
		return list;
	}

	public void removeUser(Long id) {
		User user = (User) sessionFactory.getCurrentSession().load(
				User.class, id);
		if (null != user) {
			sessionFactory.getCurrentSession().delete(user);
		}

	}
}
